#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <limits.h>
#include <sys/time.h>
 
#include "data_type.h"
#include "cube.h"
#include "cube_define.h"
#include "cube_record.h"
#include "user_define.h"
#include "record_define.h"
#include "mac_label.h"
// add para lib_include
int user_probe_init(void * sub_proc, void * para)
{
	int ret;
	// add yorself's module init func here
	return 0;
}

int user_probe_start(void * sub_proc, void * para)
{
	int ret;
	void * recv_msg;
	int type;
	int subtype;
	// add yorself's module exec func here
	while(1)
	{
		usleep(time_val.tv_usec);
		ret=ex_module_recvmsg(sub_proc,&recv_msg);
		if(ret<0)
			continue;
		if(recv_msg==NULL)
			continue;
		type=message_get_type(recv_msg);
		subtype=message_get_subtype(recv_msg);
		if(!memdb_find_recordtype(type,subtype))
		{
			printf("message format (%d %d) is not registered!\n",
			message_get_type(recv_msg),message_get_subtype(recv_msg));
			continue;
		}
		else if((type==TYPE(RECORD_DEFINE))&&(subtype==SUBTYPE(RECORD_DEFINE,RECORD)))
		{
			ret=proc_collect_userinfo(sub_proc,recv_msg);
		}
	}
	return 0;
}

int proc_collect_userinfo(void * sub_proc,void * recv_msg)
{
	int ret;
	RECORD(USER_DEFINE,CLIENT_STATE) * user_info;
	user_info = Talloc0(sizeof(*user_info));
        if(user_info ==NULL)
       		return -EINVAL;       
	user_info = proc_share_data_getpointer();
	if(user_info == NULL)
		return -EINVAL;
	message_add_expand_data(recv_msg,TYPE_PAIR(USER_DEFINE,CLIENT_STATE),user_info);
	ret=ex_module_sendmsg(sub_proc,recv_msg);
	return ret;
}
